# wx驱动测试构建文件

if meson_build
    message('meson build drivers')
    drivers_install_dir = meson.project_build_root() / 'opt/bmc/drivers'
    run_command('mkdir', '-p', drivers_install_dir, check: false)
else
    message('bingo build drivers')
    drivers_install_dir = 'opt/bmc/drivers/'
endif

# wx接口源文件
wx_interface_sources = files(
  '../../../../drivers/pcie_nic_card/wx/interface/network_adapter/cooling.cpp',
  '../../../../drivers/pcie_nic_card/wx/interface/network_port/link_info.cpp',
  '../../../../drivers/pcie_nic_card/wx/interface/network_port/lldp_receive.cpp',
  '../../../../drivers/pcie_nic_card/wx/interface/board.cpp',
  '../../../../drivers/pcie_nic_card/wx/interface/network_adapter.cpp',
  '../../../../drivers/pcie_nic_card/wx/interface/network_port.cpp',
  '../../../../drivers/pcie_nic_card/wx/interface/pcie_card.cpp',
  '../../../../drivers/pcie_nic_card/wx/interface/pcie_device.cpp',
)

test_wx_abi_sources = [
  '../../../main.cpp',
  'test_wx_abi.cpp',
  # ABI测试通过dlopen加载，不需要编译时链接
]

test_wx_card_sources = [
  '../../../main.cpp',
  'test_wx_card.cpp',
  '../../../../drivers/pcie_nic_card/wx/wx_card.cpp',
  '../../../../drivers/pcie_nic_card/wx/wx_port.cpp',
] + wx_interface_sources

test_wx_port_sources = [
  '../../../main.cpp',
  'test_wx_port.cpp',
  '../../../../drivers/pcie_nic_card/wx/wx_port.cpp',
  '../../../../drivers/pcie_nic_card/wx/wx_card.cpp',
] + wx_interface_sources

test_wx_abi = executable(
  'test_wx_abi',
  test_wx_abi_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../drivers/pcie_nic_card/wx'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
    include_directories('../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
    libimu_dep,
    libncsi_over_mctp_dep,
    libmctp_dep,
  ],
  cpp_args: ['-DUNIT_TEST'],
  link_args: ['-Wl,-rpath,' + meson.project_build_root() + '/opt/bmc/drivers'],
  install: false,
)

test_wx_card = executable(
  'test_wx_card',
  test_wx_card_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../drivers/pcie_nic_card/wx'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
    include_directories('../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
    libimu_dep,
    libncsi_over_mctp_dep,
    libmctp_dep,
    dev_deps,
  ],
  cpp_args: ['-DUNIT_TEST'],
  install: false,
)

test_wx_port = executable(
  'test_wx_port',
  test_wx_port_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../drivers/pcie_nic_card/wx'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
    include_directories('../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
    libimu_dep,
    libncsi_over_mctp_dep,
    libmctp_dep,
    dev_deps,
  ],
  cpp_args: ['-DUNIT_TEST'],
  install: false,
)

# wx接口测试
test_wx_interface_sources = [
  '../../../main.cpp',
  'interface/test_network_port.cpp',
  'interface/test_pcie_device.cpp',
  'interface/test_network_adapter.cpp',
  'interface/test_board.cpp',
  '../../../../tests/libraries/ncsi_over_mctp/mock_mctp.cpp',
] + wx_interface_sources

test_wx_interface = executable(
  'test_wx_interface',
  test_wx_interface_sources,
  include_directories: [
    include_directories('.'),
    include_directories('../../..'),
    include_directories('../../../../drivers/pcie_nic_card/wx'),
    include_directories('../../../../drivers/internal'),
    include_directories('../../../../include'),
    include_directories('../../../../gen'),
    include_directories('../../../../libraries'),
  ],
  dependencies: [
    gtest_dep,
    test_utilities_dep,
    libmcpp_deps,
    internal_dep,
    test_utils_dep,
    libimu_dep,
    libncsi_over_mctp_dep,
    libmctp_dep,
    dev_deps,
  ],
  cpp_args: ['-DUNIT_TEST'],
  install: false,
)

# 使用is_parallel: false 避免并发执行导致的资源冲突
test('test_wx_abi', test_wx_abi, timeout: 300, suite: 'wx', is_parallel: false)
test('test_wx_card', test_wx_card, timeout: 300, suite: 'wx', is_parallel: false)
test('test_wx_port', test_wx_port, timeout: 300, suite: 'wx', is_parallel: false)
test('test_wx_interface', test_wx_interface, timeout: 300, suite: 'wx', is_parallel: false) 